load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_python//python:defs.bzl", "py_binary")

package(default_applicable_licenses = ["//:license"])

UPSTREAM_VERSION = module_version().split(".bcr.", 1)[0]

[
    V_MAJOR,
    V_MINOR,
    _,
] = UPSTREAM_VERSION.split(".", 3)

expand_template(
    name = "gdbus-codegen_in",
    out = "gdbus-codegen.py",
    substitutions = {
        "@PYTHON@": "python3",
        "@DATADIR@": "@",
    },
    template = "gdbus-codegen.in",
)

expand_template(
    name = "config_py_in",
    out = "config.py",
    substitutions = {
        "@VERSION@": UPSTREAM_VERSION,
        "@MAJOR_VERSION@": V_MAJOR,
        "@MINOR_VERSION@": V_MINOR,
    },
    template = "config.py.in",
)

py_binary(
    name = "gdbus_codegen",
    srcs = [
        "config.py",
        "gdbus-codegen.py",
    ] + glob(["*.py"]),
    main = "gdbus-codegen.py",
    visibility = ["//gio:__pkg__"],
)
